const db = require( "../models" );
const logger = require( "../utils/utils.logger" );
const tools = require( "../utils/utils.tools" );
const DAO = require( "../dao/DAO" );
const POST_DAO = require( "../dao/POST_DAO" );
const information = db.information;


exports.getInfo = function ( req, res ) {
    //获取资历
    const sql = "select * from information LIMIT 1;"
    POST_DAO.doQuery( sql, data => {
      // res.send( data[0] )
        //     return res.sendResult( data, 401, null )
        if ( !data.data[0] ) {
            res.sendResultAto( {}, 200, "获取数据成功" )
        } else { 
             res.sendResultAto( data.data[ 0 ], 200, "获取数据成功" )
        }
       
        //    = function ( data, code, message )
    } )
}
exports.getInformation = function ( cb ) {
    //获取资历
    const sql = "select * from information LIMIT 1;"
    POST_DAO.doQuery( sql, data => {
        cb( data )
    })
}
// Retrieve all comment from the database.
exports.setInformation = ( req, res ) => {
    const pm = req.body;
    
    if ( !pm.id ) {
         DAO.create( information, pm, data => {
             //logger.info(`${req.method} ${req.baseUrl + req.path} *** 参数：${JSON.stringify(pm)}; 响应：${JSON.stringify(data)}`);
             res.sendResult( data )
         } )
    } else { 
         DAO.update( information, pm, {
             id: pm.id
         }, data => {
             res.sendResult( data )
         } )
    }
    
};





